
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings({"all"})
public class Generic_ {
    public static void main(String[] args) {
     Dao dao=new Dao();
     dao.save("123",new User("123",12,"xx"));
     dao.get("123");
     dao.update("456",new User("456",13,"xxx"));
     dao.list();
     dao.delete("123");
     System.out.println(dao);
    }
}
class User {
    private String id;
    private int age;
    private String name;

    public User(String id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
class Dao<T>{
    Map<String,T> map=new HashMap<>();
    public void save(String id,T entity){
        map.put(id,entity);
    }
    public T get(String id){
       return map.get(id);
    }
    public void update(String id,T entity){
        map.put(id,entity);
    }
    public List<T>list(){
        List<T> list=new ArrayList<>();
        for (String s : map.keySet()) {
            list.add(map.get(s));
        }
        return list;
    }
    public void delete(String id){
        map.remove(id);
    }

    @Override
    public String toString() {
        return "Dao{" +
                "map=" + map +
                '}';
    }
}